package com.wx.service.impl;

import com.wx.dao.BillDao;
import com.wx.dao.PatientDao;
import com.wx.dao.TransactionDao;
import com.wx.dao.impl.BillDaoImpl;
import com.wx.dao.impl.PatientDaoImpl;
import com.wx.dao.impl.TransactionDaoImpl;
import com.wx.domain.Patient;
import com.wx.domain.Transaction;
import com.wx.service.TransactionService;

import java.util.List;

public class TransactionServiceImpl implements TransactionService {
    TransactionDao transactionDao=new TransactionDaoImpl();
    BillDao billDao=new BillDaoImpl();
    PatientDao patientDao=new PatientDaoImpl();
    @Override
    public List<Transaction> findByPatientId(String patientId) {
        return transactionDao.findByPatientId(patientId);
    }

    @Override
    public boolean handlePayment(String billsId, String patientId, Double money) {
        double wallet = patientDao.getWalletById(patientId);
        if (wallet<money){
            return false;
        }
        wallet=wallet-money;
        patientDao.paymentMoney(wallet,patientId);
        billDao.paymentMoney(billsId);
        transactionDao.addTransaction(0-money,patientId);
        return true;
    }
}
